package com.lz.ccjdemo.utils;

import android.content.Context;
import android.graphics.Typeface;
import android.widget.TextView;

/**
 * 字体设置
 */
public class TypefaceSizeUtils {
    private static TypefaceSizeUtils instance;

    private Typeface typefaceBold,typefaceMedium,typefaceRegular,currTypeface;

    public static TypefaceSizeUtils getInstance(Context context) {
        if (instance == null) {
            synchronized (TypefaceSizeUtils.class) {
                instance = new TypefaceSizeUtils(context);
            }
        }
        return instance;
    }

    private TypefaceSizeUtils(Context context) {
        typefaceBold = Typeface.createFromAsset(context.getAssets(), "fonts/DIN-Bold.otf");
        typefaceMedium = Typeface.createFromAsset(context.getAssets(), "fonts/DIN-Medium.otf");
        typefaceRegular = Typeface.createFromAsset(context.getAssets(), "fonts/DIN-Regular.otf");
        currTypeface=typefaceRegular;
    }

    public void setTypeface(TextView... tvs) {
        for (TextView tv : tvs) {
            switch (tv.getTypeface().getStyle()){
                case Typeface.BOLD:
                    //加粗
                    tv.setTypeface(typefaceBold);
                    currTypeface=typefaceBold;
                    break;
                case Typeface.NORMAL:
                    //常规
                default:
                    tv.setTypeface(typefaceRegular);
                    currTypeface=typefaceBold;
                    break;
            }
        }

    }

    public Typeface getTypeface() {
        return currTypeface;
    }
}
